
package com.googlecode.xmltojava.xmlparser;

import java_cup.runtime.*;
import java.io.IOException;

import static com.googlecode.xmltojava.xmlparser.ParserSym.*;

%%

%class LexerLex
//%standalone
%unicode
%line
%column

%public
%final
// %abstract

%cupsym ParserSym
%cup
// %cupdebug

%init{
	// TODO: code that goes to constructor
%init}

%{
	private Symbol sym(int type)
	{
		return sym(type, yytext());
	}

	private Symbol sym(int type, Object value)
	{
		return new Symbol(type, yyline, yycolumn, value);
	}

	private void error()
	throws IOException
	{
		throw new IOException("illegal text at line = "+yyline+", column = "+yycolumn+", text = '"+yytext()+"'");
	}
%}

tLF         =   [\n\r]*
tSP         =   [\ \t]*
tkHeader	=   \<\?[^<>?]*\?\>

tkOpenTag   =   \<{tSP}
tkCloseTag  =   {tSP}\>
tkBSlash    =   {tSP}\/{tSP}

tkCal       =   calendar
tkEvts      =   events
tkEvt       =   event
tkDStart    =   dstart
tkDEnd      =   dend
tkDStamp    =   dtstamp
tkSummary   =   summary
tkTodos     =   todos
tkTodo		=  	todo
tkOrganizer	= 	organizer
tkJournals	= 	journals
tkJournal	= 	journal
tkDesc		= 	description
tkStatus    =   status
tkCategories=   categories
tkDuration  =   duration

tkOther  =   ([^<>\ \t\n\r\/])([^<>]|{tSP}|{tLF})*
%%
{tSP}|{tLF}   { }
{tkHeader}    { System.out.print("Header");}
{tkCal}		  { System.out.print("CAL"); return new Symbol(ParserSym.kCAL);      }
{tkEvts}	  { System.out.print("EVTS"); return new Symbol(ParserSym.kEVTS);     }
{tkEvt}		  { System.out.print("EVT"); return new Symbol(ParserSym.kEVT);      }
{tkDStart}	  { System.out.print("DSTART"); return new Symbol(ParserSym.kDSTART);   }
{tkDEnd}	  { System.out.print("DEND"); return new Symbol(ParserSym.kDEND);     }
{tkDStamp}	  { System.out.print("DSTAMP"); return new Symbol(ParserSym.kDSTAMP);   } 
{tkSummary}	  { System.out.print("SUMMARY"); return new Symbol(ParserSym.kSUMMARY);  }
{tkTodos}	  { System.out.print("TODOS"); return new Symbol(ParserSym.kTODOS);    }
{tkTodo}	  { System.out.print("TODO"); return new Symbol(ParserSym.kTODO);     }
{tkOrganizer} { System.out.print("ORGANIZER"); return new Symbol(ParserSym.kORGANIZER);}
{tkJournals}  { System.out.print("JOURNALS"); return new Symbol(ParserSym.kJOURNALS); }
{tkJournal}   { System.out.print("JOURNAL"); return new Symbol(ParserSym.kJOURNAL);  }
{tkDesc}	  { System.out.print("DESC"); return new Symbol(ParserSym.kDESC);     }
{tkStatus}    { System.out.print("STATUS"); return new Symbol(ParserSym.kSTATUS); }
{tkCategories} {System.out.print("CATEGORIES"); return new Symbol(ParserSym.kCATEGORIES); }
{tkDuration}  { System.out.print("DURATION"); return new Symbol(ParserSym.kDURATION); }

{tkOpenTag}   { System.out.print("[<]"); return new Symbol(ParserSym.kTAGOPEN);  }
{tkCloseTag}  { System.out.print("[>]"); return new Symbol(ParserSym.kTAGCLOSE); }
{tkBSlash}    { System.out.print("[/]"); return new Symbol(ParserSym.kBSLASH);   }
{tkOther}     { System.out.print("Testo"); return new Symbol(ParserSym.kOTHER, yytext());    }